<template>
  <el-dialog :visible.sync="isShow" :before-close="handleCancelModal" :close-on-click-modal="false" width="500px">
    <span slot="title" v-text="'批量修改用户投标权限'" />
    <!-- 数据表单 -->
    <el-form ref="formParams" :model="formParams" label-width="140px" size="small" style="padding-right: 40px">
      <el-form-item prop="can_bid" label="是否可参与投标：">
        <el-radio-group v-model="formParams.can_bid" size="mini">
          <el-radio-button :label="0"><span style="padding: 0 5px">不可</span></el-radio-button>
          <el-radio-button :label="1"><span style="padding: 0 5px">可以</span></el-radio-button>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <!-- 提交按钮 -->
    <div slot="footer" class="dialog-footer">
      <el-button size="small" :disabled="isSubmit" @click="handleCancelModal">取 消</el-button>
      <el-button type="primary" size="small" :loading="isSubmit" @click="handleSubmitForm">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { updateAll } from '@/api/user'

export default {
  props: {
    'isShow': { type: Boolean, default: true },
    'params': { type: Object, default: null }
  },
  data: function() {
    return {
      isSubmit: false,
      formParams: {
        can_bid: 0
      }
    }
  },
  mounted: function() {

  },
  methods: {
    handleSubmitForm() {
      this.isSubmit = true
      const params = {
        ...this.params,
        can_bid: this.formParams.can_bid
      }
      updateAll(params).then(() => {
        this.$emit('on-cancel-modal', 'showExtra', true)
      }).catch(() => {
        this.isSubmit = false
      })
    },
    // 取消弹出框
    handleCancelModal(refresh = false) {
      if (!this.isSubmit) {
        this.$emit('on-cancel-modal', 'showExtra', refresh)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.partition-container {
  display: flex;
  .partition-left {
    flex-grow: 1;
    margin-right: 15px;
  }
  .partition-right {
    width: 200px;
    height: 262px;
    border: 1px solid #DCDFE6;
    .title {
      height: 31px;
      font-size: 14px;
      font-weight: 700;
      line-height: 31px;
      padding-left: 8px;
      background-color: #f2f2f2;
    }
    .rule-main {
      height: 227px;
      margin-top: 1px;
      overflow-y: scroll;
      .el-tree {
        margin-top: 5px;
      }
    }
  }
}
</style>
